package com.ljh.filter;



import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @Author grung
 * @Date 2020/10/8 22:04
 * @Version 1.0
 */

@Activate(group = {"provider"})
public class TransportIPFilter implements Filter {
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        //获取请求调用的方法
        String methodName = invocation.getMethodName();

        //判断请求方法
        if ("getUser".equalsIgnoreCase(methodName)){

            //获取请求该getUser()方法的IP地址
            String remoteHost = RpcContext.getContext().getRemoteHost();
            System.out.println("请求IP地址："+remoteHost);
        }
        return invoker.invoke(invocation);
    }
}
